<?php

/*
 *
 * BEGIN canvas_creator.php
 *
 *
 * HTML5 Canvas Creator
 * @Description: The class creates HTML5 canvases
 * @Authors: Salman, Wits University
 * @Copyright: © Wits University 2011 - All Rights Reserved
 * @License: BSD License (http://www.linfo.org/bsdlicense.html)
 *
 *
 * BEGIN CHANGELOG
 * Developers working on thee files are REQUIRED to maintain this CHANGELOG.
 * Please ensure you follow the Changelog Guidelines: http://code.google.com/p/dazzler/wiki/DazzlerDevelopGuideline?ts=1315476570&updated=DazzlerDevelopGuideline
 * !==================================================================================================================================================================
 *
 * VERSION 1.0.0
 * 	+ File Created, Salman, 20 September 2011
 *
 * ==================================================================================================================================================================!
 * END CHANGELOG
 */


/* * *****************************************************************************************************************************************************************
 *
 * BEGIN Direct Call Check
 *
  /***************************************************************************************************************************************************************** */
global $doNotCallThisScriptDirectly;
if ($doNotCallThisScriptDirectly != 1) {
    /* Read the ini language file */
    $ini_lang_array = array();
    $clientlang = explode(",", strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']));
    $lang_ini_array = (file_exists("lang/" . trim($clientlang[0]) . ".ini")) ? parse_ini_file("lang/" . trim($clientlang[0]) . ".ini", true) : parse_ini_file("lang/en.ini", true);
    die($lang_ini_array['ERRORS']['doNotCallThisScriptDirectly']);
}
/* * *****************************************************************************************************************************************************************
 *
 * END Direct Call Check
 *
  /***************************************************************************************************************************************************************** */

/*
 * You can add other properties here like the postion of the canvas and other
 * css style
 */

class canvascreator extends baseClass {
    /* !
     * \brief An integer to store the height of the canvas
     */

    private $canvasHeight;

    /* !
     * \brief An integer to store the width of the canvas
     */
    private $canvasLength;

    /**
     * \brief Standard constructor to initialize private data members of the class.
     * \note If height or length arguments are not given, they will default to
     * 800 pixels.
     */
    public function __construct($canvas_height=800, $canvas_length=800) {
        $this->canvasHeight = $canvas_height;
        $this->canvasLength = $canvas_length;
    }

    private function buildLiveMatchCanvas() {
        $parseSiteConfig = new parsesiteconfig();
        $rootpath = $parseSiteConfig->getRootPath();
        $loadType = $parseSiteConfig->getLoadType();

        $cricketpitchpath = "$rootpath/themes/$loadType/custom/images/commentary/cricket_pitch.jpg";

        $canvasErrorMessage = ' <p>Unfortunately, your browser is currently unsupported by our web
        application.  We are sorry for the inconvenience. Please use one of the
        supported browsers listed below, or draw the image you want using an
        offline tool.</p>
        <p>Supported browsers: <a href="http://www.opera.com"> Opera</a>,&nbsp;
        <a href="http://www.mozilla.com">Firefox<a/>,&nbsp;
        <a href="http://www.apple.com/safari">Safari</a>&nbsp;and&nbsp;
        <a href="http://www.konqueror.org">Konqueror</a>';
        $liveMatchCanvas = NULL;
        $liveMatchCanvas = "<div id='gameViewer' style='position:relative;  width:800px; height:800px; '>";
        //$gameViewer = "<div id='gameViewer' style='position:absolute;  width:$this->canvasLength px; height:$this->canvasHeight px; border: 2px solid  #06F;background-color:green;'>";
//        $baseCanvas = "<div id='C1' class='gameCanvas' style='position:absolute;  width:$this->canvasLength px; height:$this->canvasHeight px; border:solid; z-index:1;'><canvas id='baseCanvas'  width=$this->canvasLength height=$this->canvasHeight></canvas></div>";
//       $liveMatchCanvas .= "<div id='C1' class='gameCanvas' style='position:relative; left:0px; top:0px;  width:$this->canvasLength px; height:$this->canvasHeight px;  z-index:20;'><img id='cricketh_pitch'  width=$this->canvasLength height=$this->canvasHeight src=$cricketpitchpath alt='Cricket Field' /></div>";
        $liveMatchCanvas .= "<img id='cricketh_pitch'  width=$this->canvasLength height=$this->canvasHeight src=$cricketpitchpath alt='Cricket Field' style='position:relative; left:0px; top:0px;  width:$this->canvasLength px; height:$this->canvasHeight px;  z-index:20;' />";
        $liveMatchCanvas .= "<canvas id='baseCanvas'  width=$this->canvasLength height=$this->canvasHeight style='position:relative; left:0px; top:-800px; width:$this->canvasLength px; height:$this->canvasHeight px; border: 2px solid  #06F; z-index:50;'>$canvasErrorMessage</canvas>";
//          $liveMatchCanvas .= "<div id='C2' class='gameCanvas' style='position:relative; left:0px; top:-800px; width:$this->canvasLength px; height:$this->canvasHeight px; z-index:50;'><canvas id='baseCanvas'  width=$this->canvasLength height=$this->canvasHeight>$canvasErrorMessage</canvas></div>";
        //  $highlightObjectCanvas = "<div id='C3' class='gameCanvas' style='position:relative; left:0px; top:-1600px; width:$this->canvasLength px; height:$this->canvasHeight px; z-index:15;'><canvas id='highlightObjectCanvas'  width=$this->canvasLength height=$this->canvasHeight>$canvasErrorMessage</canvas></div>";
        //  $dynamicObjectCanvas = "<div id='C4' class='gameCanvas' style='position:relative; left:0px; top:-2400px; width:$this->canvasLength px; height:$this->canvasHeight px; border: 2px solid  #06F; z-index:20;'><canvas id='dynamicObjectCanvas'  width=$this->canvasLength height=$this->canvasHeight>$canvasErrorMessage</canvas></div>";
        $liveMatchCanvas .="</div>";

        return $liveMatchCanvas;
    }

    /**
     * \brief This member function builds the canvas.
     * \note The game viewers width and height is set manually.
     */
    private function buildCanvas() {
        $parseSiteConfig = new parsesiteconfig();
        $rootpath = $parseSiteConfig->getRootPath();
        $loadType = $parseSiteConfig->getLoadType();

        $cricketpitchpath = "$rootpath/themes/$loadType/custom/images/commentary/cricket_pitch.png";
        $cricketFieldingPositionsPath = "$rootpath/themes/$loadType/custom/images/commentary/cricket_pitch_fieldingpositions_righthand.png";


        $postOffset = $this->canvasLength / 2;
        $postOffsetX = -$postOffset . "px";

        $postOffset = 0;
        $postOffsetY = $postOffset . "px";

        $canvasErrorMessage = ' <p>Unfortunately, your browser is currently unsupported by our web
        application.  We are sorry for the inconvenience. Please use one of the
        supported browsers listed below, or draw the image you want using an
        offline tool.</p>
        <p>Supported browsers: <a href="http://www.opera.com"> Opera</a>,&nbsp;
        <a href="http://www.mozilla.com">Firefox<a/>,&nbsp;
        <a href="http://www.apple.com/safari">Safari</a>&nbsp;and&nbsp;
        <a href="http://www.konqueror.org">Konqueror</a>';
        $gameViewer = "<div id='gameViewer' style='position:relative;  width:800px; height:800px; '>";
        //$gameViewer = "<div id='gameViewer' style='position:absolute;  width:$this->canvasLength px; height:$this->canvasHeight px; border: 2px solid  #06F;background-color:green;'>";
//        $baseCanvas = "<div id='C1' class='gameCanvas' style='position:absolute;  width:$this->canvasLength px; height:$this->canvasHeight px; border:solid; z-index:1;'><canvas id='baseCanvas'  width=$this->canvasLength height=$this->canvasHeight></canvas></div>";

        $baseCanvas = "<div id='C1' class='gameCanvas' style='position:relative; left:0px; top:0px;  width:$this->canvasLength px; height:$this->canvasHeight px;  z-index:5;'><img id='cricketh_pitch'  width=$this->canvasLength height=$this->canvasHeight src=$cricketpitchpath alt='Cricket Field' /></div>";
        $staticObjectCanvas = "<div id='C2' class='gameCanvas' style='position:relative; left:0px; top:-800px; width:$this->canvasLength px; height:$this->canvasHeight px; z-index:10;'><img id='cricketh_fielding_positions'  width=$this->canvasLength height=$this->canvasHeight src=$cricketFieldingPositionsPath alt='Cricket Fialding_Positions' /></div>";
        $highlightObjectCanvas = "<div id='C3' class='gameCanvas' style='position:relative; left:0px; top:-1600px; width:$this->canvasLength px; height:$this->canvasHeight px; z-index:15;'><canvas id='highlightObjectCanvas'  width=$this->canvasLength height=$this->canvasHeight>$canvasErrorMessage</canvas></div>";
        $dynamicObjectCanvas = "<div id='C4' class='gameCanvas' style='position:relative; left:0px; top:-2400px; width:$this->canvasLength px; height:$this->canvasHeight px; border: 2px solid  #06F; z-index:20;'><canvas id='dynamicObjectCanvas'  width=$this->canvasLength height=$this->canvasHeight>$canvasErrorMessage</canvas></div>";
        $closerForGameViewer = "</div>";




        return $canvas = $gameViewer . $baseCanvas . $staticObjectCanvas . $highlightObjectCanvas . $dynamicObjectCanvas . $closerForGameViewer;
    }

    public function getLiveMatchCanvas() {
        return $this->buildLiveMatchCanvas();
    }

    /**
     * \brief This member function get the canvas.
     * \return A built html canvas.
     */
    public function getCanvas() {
        return $this->buildCanvas();
    }

}

?>
